#include <iostream>

using namespace std;

const int N = 2e5 + 10;

int f[N];
int n;
int main()
{
	cin >> n;
	f[0] = 0;
	int ret = - 1e9;
	for (int i = 1; i <= n; i++)
	{
		int x; cin >> x;
		f[i] = max(x, f[i - 1] + x);
		ret = max(ret, f[i]);
	}
	cout << ret << endl;
	return 0;
}
  











